﻿using System;

namespace PickGold.Base.OCR.QRCode.Render
{
	public class FixedModuleSize : ISizeCalculation
	{
		private int _ModuleSize;
		private int _QuietZoneModule;

		/// <summary>
		/// Module pixel size. Have to greater than zero
		/// </summary>
		public int ModuleSize
		{
			get
			{
				return this._ModuleSize;
			}
			set
			{
				if (value <= 0)
					throw new ArgumentOutOfRangeException();

				this._ModuleSize = value;
			}
		}

		/// <summary>
		/// Number of quietZone modules
		/// </summary>
		public int QuietZoneModules
		{
			get
			{
				return this._QuietZoneModule;
			}
			set
			{
				this._QuietZoneModule = value;
			}
		}

		/// <summary>
		/// FixedModuleSize is strategy for rendering QrCode with fixed module pixel size.
		/// </summary>
		/// <param name="moduleSize">Module pixel size</param>
		/// <param name="quietZoneModules">number of quiet zone modules</param>
		public FixedModuleSize(int moduleSize, int quietZoneModules)
		{
			this._ModuleSize = moduleSize;
			this._QuietZoneModule = quietZoneModules;
		}

		/// <summary>
		/// Interface function that use by Rendering class.
		/// </summary>
		/// <param name="matrixWidth">QrCode matrix width</param>
		/// <returns>Module pixel size and QrCode pixel width</returns>
		public DrawingSize GetSize(int matrixWidth)
		{
			var i = this._QuietZoneModule;
			i = i * 2 + matrixWidth;
			i = i * this._ModuleSize;
			return new DrawingSize(this._ModuleSize, i, this._QuietZoneModule);
		}
	}
}
